Skip to content

Cover hydrating mangled keys that all resolve to the object's own scope - #31

Merged
nicolas-grekas merged 1 commit into
mainfrom
hydrate-own-scope-mangled-keys
Aug 7, 2026
Merged

Cover hydrating mangled keys that all resolve to the object's own scope#31
nicolas-grekas merged 1 commit into
mainfrom
hydrate-own-scope-mangled-keys

Conversation

@nicolas-grekas

Copy link
Copy Markdown
Member

Regression insurance mirroring symfony/polyfill#643, which fixes a deepclone_hydrate() bug in the polyfill: hydrating (array) $obj failed with Error: Cannot access property starting with "\0" whenever every mangled key resolved to the object's own class scope, e.g.

class Foo { protected $prot; private $priv; }

deepclone_hydrate(Foo::class, (array) new Foo());

The extension is not affected: it resolves each key to its (scope, real name) individually, so there is no path that writes a mangled key verbatim. But the existing round trip here hydrates Bar, whose array cast includes the parent-scoped "\0Foo\0priv", and that one key is enough to make an implementation re-key the whole array, masking whether the own-scope keys would have been handled on their own. The polyfill's mirror test had the same blind spot, which is why the bug shipped.

This adds the isolated case: a class whose every mangled key resolves to itself, which is what (array) $obj yields for any class declaring only its own protected and private properties.

Test-only, no behavior change. Verified green against PHP 8.4 and 8.5 (41/41 and 48/48).

The existing round trip hydrates a child class, so its array cast carries a
parent-scoped key. That key alone can force an implementation to re-key the
whole array to real property names, hiding whether the own-scope mangled keys
would have been handled. Hydrate a class whose every mangled key resolves to
itself, which is what (array) $obj yields for any class declaring only its own
protected and private properties.
@nicolas-grekas
nicolas-grekas merged commit 499c485 into main Aug 7, 2026
23 of 35 checks passed
@nicolas-grekas
nicolas-grekas deleted the hydrate-own-scope-mangled-keys branch August 7, 2026 06:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant